import {useState,useReducer} from "react";
import {createModel} from "hox";

function useUserName() {
    const initalState = {
        username:'',
        role:''
    }
    const [user,dispatch] = useReducer((state,action)=>{
        switch (action.type) {
            case 'login':
                return {username:action.username,role:action.role}
            default:
                return state
        }
    },initalState)
    const loginReducer = (obj) =>{dispatch(obj)}
    return  {
        user,
        loginReducer
    };
}

export default createModel(useUserName)